点赞实体类（Like）

package com.example.entity;

import lombok.Data;

@Data
public class Like {
    private String id;
    private String userId;        // 用户ID
    private String goodsId;       // 商品ID
    private Date createTime;      // 点赞时间
}
收藏实体类（Favorite）

package com.example.entity;

import lombok.Data;

@Data
public class Favorite {
    private String id;
    private String userId;        // 用户ID
    private String goodsId;       // 商品ID
    private Date createTime;      // 收藏时间
}
评论实体类（Comment）

package com.example.entity;

import lombok.Data;

@Data
public class Comment {
    private String id;
    private String userId;        // 用户ID
    private String goodsId;       // 商品ID
    private String content;       // 评论内容
    private Date createTime;      // 评论时间
}
点赞Mapper接口（LikeMapper）

package com.example.mapper;

import com.example.entity.Like;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface LikeMapper {
    @Select("SELECT * FROM likes WHERE user_id = #{userId} AND goods_id = #{goodsId}")
    Like getLikeByUserIdAndGoodsId(String userId, String goodsId);

    int insertLike(Like like);
    int deleteLikeById(String id);
}
收藏Mapper接口（FavoriteMapper）

package com.example.mapper;

import com.example.entity.Favorite;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface FavoriteMapper {
    @Select("SELECT * FROM favorites WHERE user_id = #{userId}")
    List<Favorite> getFavoritesByUserId(String userId);

    int insertFavorite(Favorite favorite);
    int deleteFavoriteById(String id);
}
评论Mapper接口（CommentMapper）

package com.example.mapper;

import com.example.entity.Comment;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CommentMapper {
    @Select("SELECT * FROM comments WHERE goods_id = #{goodsId}")
    List<Comment> getCommentsByGoodsId(String goodsId);

    int insertComment(Comment comment);
}
点赞Service层（LikeService）

package com.example.service;

import com.example.entity.Like;
import com.example.mapper.LikeMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LikeService {
    @Autowired
    private LikeMapper likeMapper;

    public Like getLikeByUserIdAndGoodsId(String userId, String goodsId) {
        return likeMapper.getLikeByUserIdAndGoodsId(userId, goodsId);
    }

    public void addLike(Like like) {
        likeMapper.insertLike(like);
    }

    public void deleteLike(String id) {
        likeMapper.deleteLikeById(id);
    }
}
收藏Service层（FavoriteService）

package com.example.service;

import com.example.entity.Favorite;
import com.example.mapper.FavoriteMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FavoriteService {
    @Autowired
    private FavoriteMapper favoriteMapper;

    public List<Favorite> getFavoritesByUserId(String userId) {
        return favoriteMapper.getFavoritesByUserId(userId);
    }

    public void addFavorite(Favorite favorite) {
        favoriteMapper.insertFavorite(favorite);
    }

    public void deleteFavorite(String id) {
        favoriteMapper.deleteFavoriteById(id);
    }
}
评论Service层（CommentService）

package com.example.service;

import com.example.entity.Comment;
import com.example.mapper.CommentMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommentService {
    @Autowired
    private CommentMapper commentMapper;

    public List<Comment> getCommentsByGoodsId(String goodsId) {
        return commentMapper.getCommentsByGoodsId(goodsId);
    }

    public void addComment(Comment comment) {
        commentMapper.insertComment(comment);
    }
}
点赞Controller层（LikeController）

package com.example.controller;

import com.example.entity.Like;
import com.example.service.LikeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/like")
public class LikeController {
    @Autowired
    private LikeService likeService;

    @PostMapping
    public void addLike(@RequestBody Like like) {
        likeService.addLike(like);
    }

    @DeleteMapping("/{id}")
    public void deleteLike(@PathVariable String id) {
        likeService.deleteLike(id);
    }
}
收藏Controller层（FavoriteController）

package com.example.controller;

import com.example.entity.Favorite;
import com.example.service.FavoriteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/favorite")
public class FavoriteController {
    @Autowired
    private FavoriteService favoriteService;

    @GetMapping("/{userId}")
    public List<Favorite> getFavoritesByUserId(@PathVariable String userId) {
        return favoriteService.getFavoritesByUserId(userId);
    }

    @PostMapping
    public void addFavorite(@RequestBody Favorite favorite) {
        favoriteService.addFavorite(favorite);
    }

    @DeleteMapping("/{id}")
    public void deleteFavorite(@PathVariable String id) {
        favoriteService.deleteFavorite(id);
    }
}
评论Controller层（CommentController）
package com.example.controller;

import com.example.entity.Comment;
import com.example.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/comment")
public class CommentController {
    @Autowired
    private CommentService commentService;

    @GetMapping("/{goodsId}")
    public List<Comment> getCommentsByGoodsId(@PathVariable String goodsId) {
        return commentService.getCommentsByGoodsId(goodsId);
    }

    @PostMapping
    public void addComment(@RequestBody Comment comment) {
        commentService.addComment(comment);
    }
}
